package deep.projects.newsapp.beans;

import org.json.JSONException;
import org.json.JSONObject;

/**
 * User 类用于存放用户信息
 * @author 吾心无待 于2016年03月05日
 */
public class User{
    private int id;//用户id
    private String mobile;//手机号码
    private String username="";//用户名
    private String gender="男";//性别
    private String birthday="1980-1-1";//生日
    private String avatar="";//头像
    private int level=0;//用户等级

    public int getId() {
        return id;
    }

    public void setId(int id) {
        this.id = id;
    }

    public String getMobile() {
        return mobile;
    }

    public void setMobile(String mobile) {
        this.mobile = mobile;
    }

    public String getUsername() {
        return username;
    }

    public void setUsername(String username) {
        this.username = username;
    }

    public String getGender() {
        return gender;
    }

    public void setGender(String gender) {
        this.gender = gender;
    }

    public String getBirthday() {
        return birthday;
    }

    public void setBirthday(String birthday) {
        this.birthday = birthday;
    }

    public String getAvatar() {
        return avatar;
    }

    public void setAvatar(String avatar) {
        this.avatar = avatar;
    }

    public int getLevel() {
        return level;
    }

    public void setLevel(int level) {
        this.level = level;
    }

    /**
     *  从JSONObject 序列化出 User 对象
     * @param obj
     * @return
     * @throws JSONException
     */
    public static User from(JSONObject obj) throws JSONException{
        User user = new User();
        user.setId(obj.getInt("id"));
        user.setMobile(obj.getString("mobile"));
        user.setGender(obj.getString("gender"));
        user.setBirthday(obj.getString("birthday"));
        user.setUsername(obj.getString("username"));
        user.setAvatar(obj.getString("avatar"));
        user.setLevel(obj.getInt("level"));
        return user;
    }

    public static User create(int userid,String mobile){
        User user = new User();
        user.setId(userid);
        user.setMobile(mobile);
        return user;
    }
}
